package Service.ServiceImpl;

import Dao.DaoImpl.StudentDaoImpl;
import Dao.StudentDao;
import Pojo.Student;
import Service.StudentService;

import java.util.List;

/**
 * Created by MI on 2021/7/6.
 */
public class StudentServiceImpl implements StudentService {
    /**
     * 根据用户名查询返回用户对象
     * @param username 用户名
     * @return s用户对象
     */
    @Override
    public Student findUserByName(String username) {

        StudentDao studentDao = new StudentDaoImpl();
        Student s = studentDao.findUserByName(username);
        return s;
    }

    /**
     * 注册判断是否成功
     * @param s 传入用户对象
     * @return  返回是否成功
     */
    @Override
    public int InsertNewUser(Student s) {

        StudentDao studentDao = new StudentDaoImpl();
        int count = studentDao.InsertNewUser(s);
        return count;
    }

    /**
     * 展示所有用户信息
     * @return
     */
    @Override
    public List<Student> findAllUser() {
        StudentDao studentDao = new StudentDaoImpl();
        List<Student> list = studentDao.findAllUser();
        if(list!=null){
            return  list;
        }
            return null;
    }

    /**
     * 根据id删除用户
     * @param id
     * @return flag
     */
    @Override
    public boolean deleteUserById(Integer id) {
        StudentDao studentDao = new StudentDaoImpl();
        int count = studentDao.deleteUserById(id);
        if (count>0){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 修改用户
     * @param s
     * @return flag
     */
    @Override
    public boolean updateUserById(Student s) {
        StudentDao studentDao = new StudentDaoImpl();
        int count = studentDao.updateUserById(s);
        if (count>0){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 根据id查询用户
     * @param id 学号
     * @return 对象
     */
    @Override
    public Student findUserById(Integer id) {
        StudentDao studentDao = new StudentDaoImpl();
        Student s = studentDao.findUserById(id);
        return s;
    }
}
